package cn.scw.project.goods.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.goods.domain.netework.bean.GCouponAddReq;
import cn.scw.project.goods.domain.netework.bean.GCouponListReq;
import cn.scw.project.goods.domain.vo.GCouponVo;
import cn.scw.project.goods.service.IGCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠券Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "优惠券")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/goods/coupon")
public class GCouponController extends BaseController {
    @Autowired
    private IGCouponService gCouponService;

    @ApiOperation("查询优惠券")
    //@PreAuthorize("@ss.hasPermi('goods:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(GCouponListReq req) {
        startPage();
        List<GCouponVo> list = gCouponService.selectGCouponList(req);
        return getDataTable(list);
    }

    @ApiOperation("查询可领取优惠券")
    @GetMapping("/usable/list")
    public TableDataInfo usableList() {
        startPage();
        List<GCouponVo> list = gCouponService.selectUsableList();
        return getDataTable(list);
    }

    @ApiOperation("查询优惠券详情")
    //@PreAuthorize("@ss.hasPermi('goods:coupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gCouponService.selectGCouponVoById(id));
    }

    @ApiOperation("新增优惠券")
    //@PreAuthorize("@ss.hasPermi('goods:coupon:add')")
    @Log(title = "优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(GCouponAddReq req) {
        return toAjax(gCouponService.insertGCoupon(req));
    }

    @ApiOperation("修改优惠券")
    //@PreAuthorize("@ss.hasPermi('goods:coupon:edit')")
    @Log(title = "优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(GCouponAddReq req) {
        return toAjax(gCouponService.updateGCoupon(req));
    }

    @ApiOperation("删除优惠券")
    //@PreAuthorize("@ss.hasPermi('goods:coupon:remove')")
    @Log(title = "优惠券", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gCouponService.deleteGCouponByIds(ids));
    }
}
